package hp.com.servlet.UsersServlet;

import hp.com.entity.Users;
import hp.com.service.UsersService;
import hp.com.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/Register")
public class RegistServlet extends HttpServlet {
    private UsersService usersService = new UsersServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp){
        try {
            String username = req.getParameter("username");
            String password = req.getParameter("password");
            String phone = req.getParameter("phone");
            String email = req.getParameter("email");
            Users users = new Users();
            users.setLoginname(username);
            users.setPwd(password);
            users.setPhone(phone);
            users.setEmail(email);
            boolean b = usersService.addUsers(users);
            resp.getWriter().print(b);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
